package org.jeecg.modules.monitoring.j_monitoring.controller;

import java.util.Arrays;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.modules.monitoring.j_monitoring.entity.MColumnConfig;
import org.jeecg.modules.monitoring.j_monitoring.service.IMColumnConfigService;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;

import org.jeecg.common.system.base.controller.JeecgController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.jeecg.common.aspect.annotation.AutoLog;

 /**
 * @Description: 列设置
 * @Author: xiaoyq
 * @Date:   2023-02-12
 * @Version: V1.0
 */
@Api(tags="列设置")
@RestController
@RequestMapping("/j_monitoring/mColumnConfig")
@Slf4j
public class MColumnConfigController extends JeecgController<MColumnConfig, IMColumnConfigService> {

	/**
	 * 分页列表查询
	 *
	 * @param columnConfig
	 * @param pageNo
	 * @param pageSize
	 * @param req
	 * @return
	 */
	//@AutoLog(value = "列设置-分页列表查询")
	@ApiOperation(value="列设置-分页列表查询", notes="列设置-分页列表查询")
	@GetMapping(value = "/list")
	public Result<IPage<MColumnConfig>> queryPageList(MColumnConfig columnConfig,
													  @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
													  @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
													  HttpServletRequest req) {
		QueryWrapper<MColumnConfig> queryWrapper = QueryGenerator.initQueryWrapper(columnConfig, req.getParameterMap());
		Page<MColumnConfig> page = new Page<MColumnConfig>(pageNo, pageSize);

		IPage<MColumnConfig> pageList = service.page(page, queryWrapper);
		return Result.OK(pageList);
	}

	/**
	 *   添加
	 *
	 * @param columnConfig
	 * @return
	 */
	@AutoLog(value = "列设置-添加")
	@ApiOperation(value="列设置-添加", notes="列设置-添加")
	//@RequiresPermissions("org.jeecg.modules.monitoring:savecolumn:add")
	@PostMapping(value = "/add")
	public Result<?> add(@RequestBody MColumnConfig columnConfig) {
		service.save(columnConfig);
		return Result.OK(columnConfig);
	}

	/**
	 *  编辑
	 *
	 * @param columnConfig
	 * @return
	 */
	@AutoLog(value = "列设置-编辑")
	@ApiOperation(value="列设置-编辑", notes="列设置-编辑")
	//@RequiresPermissions("org.jeecg.modules.monitoring:savecolumn:edit")
	@RequestMapping(value = "/edit", method = {RequestMethod.PUT,RequestMethod.POST})
	public Result<String> edit(@RequestBody MColumnConfig columnConfig) {
		service.updateById(columnConfig);
		return Result.OK("编辑成功!");
	}

	/**
	 *   通过id删除
	 *
	 * @param id
	 * @return
	 */
	@AutoLog(value = "列设置-通过id删除")
	@ApiOperation(value="列设置-通过id删除", notes="列设置-通过id删除")
	//@RequiresPermissions("org.jeecg.modules.monitoring:savecolumn:delete")
	@DeleteMapping(value = "/delete")
	public Result<String> delete(@RequestParam(name="id",required=true) String id) {
		service.removeById(id);
		return Result.OK("删除成功!");
	}

	/**
	 *  批量删除
	 *
	 * @param ids
	 * @return
	 */
	@AutoLog(value = "列设置-批量删除")
	@ApiOperation(value="列设置-批量删除", notes="列设置-批量删除")
	//@RequiresPermissions("org.jeecg.modules.monitoring:savecolumn:deleteBatch")
	@DeleteMapping(value = "/deleteBatch")
	public Result<String> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
		this.service.removeByIds(Arrays.asList(ids.split(",")));
		return Result.OK("批量删除成功!");
	}

	/**
	 * 通过id查询
	 *
	 * @param id
	 * @return
	 */
	//@AutoLog(value = "列设置-通过id查询")
	@ApiOperation(value="列设置-通过id查询", notes="列设置-通过id查询")
	@GetMapping(value = "/queryById")
	public Result<MColumnConfig> queryById(@RequestParam(name="id",required=true) String id) {
		MColumnConfig columnConfig = service.getById(id);
		if(columnConfig ==null) {
			return Result.error("未找到对应数据");
		}
		return Result.OK(columnConfig);
	}

    /**
    * 导出excel
    *
    * @param request
    * @param columnConfig
    */
    //@RequiresPermissions("org.jeecg.modules.monitoring:savecolumn:exportXls")
    @RequestMapping(value = "/exportXls", method = RequestMethod.GET)
	@ApiOperation(value="列设置-导出", notes="列设置-导出")
    public ModelAndView exportXls(HttpServletRequest request, MColumnConfig columnConfig) {
        return super.exportXls(request, columnConfig, MColumnConfig.class, "列设置");
    }

    /**
      * 通过excel导入数据
    *
    * @param request
    * @param response
    * @return
    */
    //@RequiresPermissions("savecolumn:importExcel")
	@ApiOperation(value="列设置-导入", notes="列设置-导入")
    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
    public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
        return super.importExcel(request, response, MColumnConfig.class);
    }

}
